#include "DDisplay.h"

#include <stdexcept>
#include <string>

namespace pezad
{

DDisplay& DDisplay::getInstance()
{
	static DDisplay instance;

	return instance;
}

DDisplay::DDisplay()
{
	init();
}

DDisplay::~DDisplay()
{
}

void DDisplay::init()
{

	// Initialize SDL normally.
	if (SDL_Init(SDL_INIT_VIDEO) != 0)
	{
		throw std::logic_error("SDL could not initialize. Discuss.");
	}

	// Set the screen to be used for graphics.
	screen = SDL_SetVideoMode(640, 480, 0, SDL_DOUBLEBUF | SDL_ANYFORMAT | SDL_RESIZABLE);

	if (screen == NULL) {
		std::string errorMessage("SDL could not set video mode. Error: ");
		throw std::logic_error(errorMessage + SDL_GetError());
	}
}

void DDisplay::renderFrame()
{
	aalineRGBA(screen, 32, 32, 64, 64, 0x80, 0xFF, 0x80, 0xFF);
	SDL_Flip(screen);
}

}
